#include <cstdio>
#include <cstring>

const int mod = 2007;

int n, K;

int start[11][11];
int T[11][11], W[11][11];

void matrixMult( int A[11][11], int B[11][11] )
{
	int C[11][11];

	for( int i = 0; i <= K; ++i )
		for( int j = 0; j <= K; ++j ) {
			int val = 0;

			for( int k = 0; k <= K; ++k )
				val = (val + A[i][k]*B[k][j]) % mod;
			C[i][j] = val;
		}

	for( int i = 0; i < 11; ++i )
		for( int j = 0; j < 11; ++j )
			A[i][j] = C[i][j];
}

int main( void )
{
	freopen( "input.txt", "r", stdin );

	scanf( "%d %d", &n, &K );

	start[0][0] = 1;
	for( int j = 0; j <= K; ++j ) {
		T[j][j] = j;
		if( j ) T[j][j - 1] = 1;
		W[j][j] = 1;
	}

	while( n ) {
		if( n&1 ) matrixMult(W, T);
		matrixMult(T, T);
		n >>= 1;
	}
	matrixMult(W, start);

	printf("%d\n", W[K][0]);

	return 0;
}
